package org.kl.auditsupervision.web.fnd;

import java.io.FileInputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import javax.servlet.ServletOutputStream;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.activiti.engine.runtime.ProcessInstance;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.kl.auditsupervision.entity.fnd.AuditProDtl;
import org.kl.auditsupervision.entity.fnd.AuditProDtlNop;
import org.kl.auditsupervision.entity.fnd.Employee;
import org.kl.auditsupervision.entity.fnd.ZgCsNop;
import org.kl.auditsupervision.service.fnd.AuditProDtlNopService;
import org.kl.auditsupervision.service.fnd.OrgService;
import org.kl.auditsupervision.service.fnd.ZgCsNopService;
import org.kl.bf.entity.easyui.EasyuiUtils;
import org.kl.bf.utils.BasicConstants;
import org.kl.bf.utils.KLServlets;
import org.kl.bf.web.base.BasicController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springside.modules.web.MediaTypes;

/**
 *  
 * @since  2016-08-02 17:07:38
 * @see 审计明细
 */
@SuppressWarnings("deprecation")
@Controller
@RequestMapping(value = "/fnd/auditProDtlNop")
public class AuditProDtlNopController extends BasicController {

	@Autowired
	private AuditProDtlNopService auditProDtlNopService;
	@Autowired
	private ZgCsNopService zgCsNopService;
	@Autowired
	private OrgService orgService;
	
	/**
	 * 审计选择框
	 * @param pageNumber
	 * @param pageSize
	 * @param sortType
	 * @param orderType
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "dataGrids", produces = { MediaTypes.TEXT_HTML_UTF_8, MediaTypes.JSON_UTF_8 })
	@ResponseBody
	public String dataGrids(@RequestParam(value = "pageNumber", defaultValue = "1") int pageNumber,
			@RequestParam(value = "rows", defaultValue = PAGE_SIZE) int pageSize,
			@RequestParam(value = "sort", defaultValue = "createTime") String sortType,
			@RequestParam(value = "order", defaultValue = "desc") String orderType, 
			@RequestParam(value = "businessKey", defaultValue = "-1") String businessKey, Model model, ServletRequest request) {
		try{
			Map<String, Object> searchParams = KLServlets.getParametersStartingWith(request, SEARCH_PREFIX);
			Page<AuditProDtlNop> auditProDtlNop;
			//在审批页面，只显示审批的那条记录
			if (!businessKey.equals("-1")) {
				searchParams.put("EQ_id", businessKey);
				auditProDtlNop = auditProDtlNopService.getPage(searchParams, pageNumber, pageSize, sortType,orderType);
			}else{
				//queryFilter(searchParams,"training");
				auditProDtlNop =auditProDtlNopService.getPage(searchParams, pageNumber, pageSize, sortType,orderType);
			}
			return EasyuiUtils.buildEasyuiGridJsonString(auditProDtlNop.getContent(), (int) auditProDtlNop.getTotalElements());
		}catch(Exception e){
			e.printStackTrace();
			return "数据加载失败";
		}
			
	}
	
	
	 
	@RequestMapping(value = "riskDimensionStatisticList",method = RequestMethod.GET)
	public String RiskDimensionStatisticList(Model model) {
		return "fnd/riskDimensionStatisticList";
	}
	
	
	@RequestMapping(method = RequestMethod.GET)
	public String list(Model model) {
		return "fnd/auditProDtlNopList";
	}
	
	
	@RequestMapping(value = "ZRLeaderAssign")
	public String ZRLeaderAssign(@RequestParam(value = "id", defaultValue = "") String id,
			@RequestParam(value = "businessKey", defaultValue = "") String businessKey, Model model,
			HttpServletRequest request) {
		AuditProDtlNop auditProDtlNop=auditProDtlNopService.getOne(businessKey);
		model.addAttribute("auditProDtl", auditProDtlNop);
		return "fnd/auditProDtlList_ZRLeaderAssign";
	}
	
	
	@RequestMapping(value = "ZRMake")
	public String ZRMake(@RequestParam(value = "id", defaultValue = "") String id,
			@RequestParam(value = "businessKey", defaultValue = "") String businessKey, 
			@RequestParam(value = "isEdit", defaultValue = "") String isEdit,Model model,
			HttpServletRequest request) {
		model.addAttribute("isEdit", 0);
		model.addAttribute("auditProDtlId", businessKey);
		return "fnd/auditProDtlList_ZRMake";
	}
	
	@RequestMapping(value = "ZRMakeEdit")
	public String ZRMakeEdit(@RequestParam(value = "id", defaultValue = "") String id,
			@RequestParam(value = "businessKey", defaultValue = "") String businessKey, 
			@RequestParam(value = "isEdit", defaultValue = "") String isEdit,Model model,
			HttpServletRequest request) {
		model.addAttribute("isEdit", 1);
		model.addAttribute("auditProDtlId", businessKey);
		return "fnd/auditProDtlList_ZRMake";
	}

	@RequestMapping(value = "ZRExe")
	public String ZRExe(@RequestParam(value = "id", defaultValue = "") String id,
			@RequestParam(value = "businessKey", defaultValue = "") String businessKey, Model model,
			HttpServletRequest request) {
		model.addAttribute("isEdit", 0);
		return "fnd/auditProDtlList_ZRExe";
	}
	
	@RequestMapping(value = "ZRExeEdit")
	public String ZRExeEdit(@RequestParam(value = "id", defaultValue = "") String id,
			@RequestParam(value = "businessKey", defaultValue = "") String businessKey, Model model,
			HttpServletRequest request) {
		model.addAttribute("isEdit", 1);
		return "fnd/auditProDtlList_ZRExe";
	}
	
	@RequestMapping(value = "zgcs")
	public String zgcs(@RequestParam(value = "id", defaultValue = "") String id,
			@RequestParam(value = "businessKey", defaultValue = "") String businessKey, Model model,
			HttpServletRequest request) {
		AuditProDtlNop auditProDtlNop;
		if(StringUtils.isBlank(id)){
			auditProDtlNop=auditProDtlNopService.getOne(businessKey);
		}
		else{
			auditProDtlNop=auditProDtlNopService.getOne(id);
		}
		model.addAttribute("auditProDtlNop", auditProDtlNop);
		model.addAttribute("isEdit", auditProDtlNop.getConfirmFlag()==0?1:0);
		return "fnd/zgCsNopList";
	}
	
	@RequestMapping(value = "dataGrid", produces = { MediaTypes.TEXT_HTML_UTF_8, MediaTypes.JSON_UTF_8 })
	@ResponseBody
	public String dataGrid(@RequestParam(value = "auditId", defaultValue = "") String auditId,
			@RequestParam(value = "pageNumber", defaultValue = "1") int pageNumber,
			@RequestParam(value = "rows", defaultValue = PAGE_SIZE) int pageSize,
			@RequestParam(value = "sort", defaultValue = "createTime") String sortType,
			@RequestParam(value = "order", defaultValue = "desc") String orderType, 
			@RequestParam(value = "businessKey", defaultValue = "-1") String businessKey,Model model, ServletRequest request) {
		Map<String, Object> searchParams = KLServlets.getParametersStartingWith(request, SEARCH_PREFIX);
		if(StringUtils.isNotEmpty(auditId)){
			searchParams.put("EQ_auditProNop.id", auditId);
		}
		
		Page<AuditProDtlNop> auditProDtlNop;
		//在审批页面，只显示审批的那条记录
		if (!businessKey.equals("-1")) {
			searchParams.put("EQ_id", businessKey);
		}else{
			if (!isPermission("auditProNop" + ":allQuery")) {
				Employee employee = userService.getUser(getCurrentUserId()).getEmployee();
				searchParams.put("EQ_employee.id", employee.getId());
			}
		}
		auditProDtlNop = auditProDtlNopService.getPage(searchParams, pageNumber, pageSize, sortType,orderType);
		return EasyuiUtils.buildEasyuiGridJsonString(auditProDtlNop.getContent(), (int) auditProDtlNop.getTotalElements());
	}

	@RequestMapping(value = "update", method = RequestMethod.POST, produces = { MediaTypes.TEXT_HTML_UTF_8,
			MediaTypes.JSON_UTF_8 })
	@ResponseBody
	public String update(@Valid @ModelAttribute("auditProDtlNop") AuditProDtlNop auditProDtlNop,
			@RequestParam(value = "detailInserted", required = false) String detailInserted,
			@RequestParam(value = "detailUpdated", required = false) String detailUpdated, 
			@RequestParam(value = "detailDeleted", required = false) String detailDeleted, BindingResult result) {
		if(result.hasErrors()){
			return ajaxMsg(bindingMsg(result), false, null);
		}
		try{
			auditProDtlNopService.save(auditProDtlNop);
		    return ajaxMsg("保存成功", true, auditProDtlNop);
		}catch(Exception e){
			e.printStackTrace();
			return ajaxMsg("保存失败:" + e.getMessage(), false, null);
		}
	}
	
	/**
	 * 申请审批流程启动
	 * 
	 * @param id
	 * @return
	 */
	@RequiresPermissions({ "auditProDtl:update" })
	@RequestMapping(value = "apply/{id}", produces = MediaTypes.JSON_UTF_8)
	@ResponseBody
	public String apply(@PathVariable("id") String id) {
		if (StringUtils.isNotBlank(id)) {
			try {
				ProcessInstance processInstance=null;
				AuditProDtlNop rpa = auditProDtlNopService.getOne(id);
				Map<String, Object> variables = new HashMap<String, Object>();
				if (rpa != null) {
					processInstance=auditProDtlNopService.startWorkflow(rpa, variables);
				}
				return ajaxMsg("启动流程成功,processId" + processInstance.getId(), true, processInstance.getProcessInstanceId());
			} catch (Exception e) {
				e.printStackTrace();
				return ajaxMsg("申请审批流程启动失败：" + e.getMessage(), false, null);
			}
		} else {
			return ajaxMsg("申请审批流程启动失败：请刷新页面重试，申请标识未找到", false, null);
		}
	}
	
	@RequiresPermissions(value = "auditProNop:confirm")
	@RequestMapping(value = "confirm/{id}", produces = MediaTypes.JSON_UTF_8)
	@ResponseBody
	public String confirm(@PathVariable("id") String id, RedirectAttributes redirectAttributes) {
		String msg="";
		AuditProDtlNop auditProDtlNop = auditProDtlNopService.getOne(id);
		if (auditProDtlNop==null) {
			return ajaxMsg("请选择行", false, null);
		} else if (auditProDtlNop.getConfirmFlag().equals(BasicConstants.CONFIRM_STATUS_Confirm)) {
			return ajaxMsg("确认失败,不能进行2次确认！", false, null);
		}else {
			try {	
				 msg= auditProDtlNopService.confirm(auditProDtlNop);
			} catch (Exception e) {
				e.printStackTrace();
				return ajaxMsg("确认失败[" + e.getMessage() + "]", false, null);
			}
			return ajaxMsg(msg, true, null);
		}
	}
	
	@RequiresPermissions(value = "auditProNop:delete")
	@RequestMapping(value = "delete/{id}", produces = MediaTypes.JSON_UTF_8)
	@ResponseBody
	public String delete(@PathVariable("id") String id, RedirectAttributes redirectAttributes) {
		try {
			auditProDtlNopService.delete(id);
			return ajaxMsg("删除成功", true, null);
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxMsg("删除失败:" + e.getMessage(), false, null);
		}
	}
	
	@RequiresPermissions({ "auditProNop:delete" })
	@RequestMapping(value = "multiDelete", produces = MediaTypes.JSON_UTF_8)
	@ResponseBody
	public String multiDelete(@RequestParam(value = "ids", defaultValue = "") String ids) {
		String msg = "";
		try {
			msg = auditProDtlNopService.multiDelete(ids);
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxMsg("删除失败:" + e.getMessage(), false, null);
		}
		return ajaxMsg("删除成功:" + msg, true, null);
	}
	
	@RequiresPermissions("auditProNop:export")
	@RequestMapping(value = "excelExport", produces = MediaTypes.JSON_UTF_8)
	@ResponseBody
	public String excelExport(@RequestParam(value = "auditProId", defaultValue = "-1") String auditProId,
			@RequestParam(value = "pageNumber", defaultValue = "1") int pageNumber,
			@RequestParam(value = "sort", defaultValue = "id") String sortType,
			@RequestParam(value = "order", defaultValue = "desc") String orderType, Model model, ServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> searchParams = KLServlets.getParametersStartingWith(request, SEARCH_PREFIX);
		searchParams.put("EQ_auditProNop.id", auditProId);//auditProNop
		List<AuditProDtlNop> auditProDtlNop = auditProDtlNopService.searchAll(searchParams, sortType, orderType);
		//super.export(AuditProDtl.class, response, auditProDtl, "审计明细表");
		
		try{
			ServletOutputStream os=response.getOutputStream();
			response.reset();
			String filename=new String("审计整改计划".getBytes("gb2312"),"ISO8859-1")+".xls";
			response.setHeader("Content-disposition", "attachment;filename="+filename);
			response.setContentType("application/msexcel");
			String filePath=((HttpServletRequest) request).getSession().getServletContext().getRealPath("/ExcelExportTemplate/审计整改计划.xls");
			HSSFWorkbook workbook=new HSSFWorkbook(new FileInputStream(filePath));
			if(auditProDtlNop==null){
				return ajaxMsg("未找到符合条件的审计明细信息!", false,null);
			}
			 
			Set pjSet=new TreeSet<String>();//统计评价条数
			for(AuditProDtlNop apd:auditProDtlNop){
				String evaString=apd.getAuditEvaluationNo();
				if(StringUtils.isNotEmpty(evaString))
					pjSet.add(evaString);
			}
		 
			
			try{
				HSSFSheet sheet=workbook.getSheetAt(0);//获取第一个sheet
				HSSFRow row;
				HSSFCell cell=null;

				int rownum=1;//添加的起始行
				
				//设置样式;  
		        HSSFCellStyle style = workbook.createCellStyle();  
		        //设置底边框;  
		        style.setBorderBottom(HSSFCellStyle.BORDER_THIN);  
		        //设置底边框颜色;  
		        style.setBottomBorderColor(HSSFColor.BLACK.index);  
		        //设置左边框;  
		        style.setBorderLeft(HSSFCellStyle.BORDER_THIN);  
		        
		        //设置左边框颜色;  
		        style.setLeftBorderColor(HSSFColor.BLACK.index);  
		        //设置右边框;  
		        style.setBorderRight(HSSFCellStyle.BORDER_THIN);  
		        //设置右边框颜色;  
		        style.setRightBorderColor(HSSFColor.BLACK.index);  
		        //设置顶边框;  
		        style.setBorderTop(HSSFCellStyle.BORDER_THIN);  
		        //设置顶边框颜色;  
		        style.setTopBorderColor(HSSFColor.BLACK.index);  
		        //设置自动换行;  
		        style.setWrapText(true);  
		        //设置水平对齐的样式为居中对齐;  
		        style.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY);  
		        //设置垂直对齐的样式为居中对齐;  
		        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_JUSTIFY);    
		        
		        //统一字体为宋体12号
		        HSSFFont font=workbook.createFont();
		        font.setFontName("宋体");
		        font.setFontHeightInPoints((short)10);
		        style.setFont(font);
		        
		        //设定统一的前景色
		        style.setFillForegroundColor(HSSFColor.WHITE.index);
				style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
				
				//设定无前景色的格式
				HSSFCellStyle whiteStyle=workbook.createCellStyle();
				whiteStyle.cloneStyleFrom(style);
				whiteStyle.setFillForegroundColor(HSSFColor.WHITE.index);
				whiteStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		        
		        //文本格式
				HSSFCellStyle css=workbook.createCellStyle();
				css.cloneStyleFrom(style);
				DataFormat format=workbook.createDataFormat();
				css.setDataFormat(format.getFormat("@"));
				
				//“自定义yyyy/mm/dd”格式
				HSSFCellStyle dateStyle=workbook.createCellStyle();
				dateStyle.cloneStyleFrom(style);
				DataFormat format2=workbook.createDataFormat();
				dateStyle.setDataFormat(format2.getFormat("yyyy/mm/dd"));
				
				//灰色前景色 常规格式
				HSSFCellStyle grayStyle=workbook.createCellStyle();
				grayStyle.cloneStyleFrom(style);
				grayStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
				grayStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
				
				//灰色前景色 文本格式
				HSSFCellStyle grayTextStyle=workbook.createCellStyle();
				grayTextStyle.cloneStyleFrom(css);
				grayTextStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
				grayTextStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
				
				//红色字体  常规格式
				HSSFCellStyle redFontStyle=workbook.createCellStyle();
				redFontStyle.cloneStyleFrom(style);
				HSSFFont redfont=workbook.createFont();
				redfont.setFontName("宋体");
				redfont.setFontHeightInPoints((short)12);
				redfont.setColor(HSSFColor.RED.index);
				redfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
				redFontStyle.setFont(redfont);
				
				 //红色字体  文本格式
				HSSFCellStyle redTextStyle=workbook.createCellStyle();
				redTextStyle.cloneStyleFrom(redFontStyle);
				DataFormat format3=workbook.createDataFormat();
				redTextStyle.setDataFormat(format3.getFormat("@"));
		        
				Iterator<AuditProDtlNop> iterator=auditProDtlNop.iterator();
				
				//格式化日期
				SimpleDateFormat format4=new SimpleDateFormat("yyyyMMdd");
				
				 //循环评价
				Iterator pjIt=pjSet.iterator();
				
				while(pjIt.hasNext()){
					int pjRownum=rownum;//评价开始合并单元格的行号
					Object evaNoString=pjIt.next();
					List<AuditProDtlNop> evaList=auditProDtlNopService.findByAuditProNopIdAndAuditEvaluationNo(auditProId, evaNoString.toString());//findByAuditProIdAndAuditFindingEva(auditProId,evaNoString.toString());//审计发现数据
					AuditProDtlNop pjEntity=evaList.get(0);
					Set fxSet=new TreeSet<String>();//统计每条评价的发现数量
					for(AuditProDtlNop apd:evaList){
						String finString=apd.getAuditFindingNo();
						if(StringUtils.isNotEmpty(finString))
							fxSet.add(finString);
					}
					
					Iterator fxIt=fxSet.iterator();
					if(fxSet.size()==0){
						//没有发现
						    row=sheet.createRow(rownum);
							//序号
							myCreateCell(0,rownum+"", row, cell, style);
							//审计监察评价
							myCreateCell(1,pjEntity!=null?pjEntity.getAuditEvaluation():"", row, cell, style);
							
							//审计发现
							myCreateCell(2, "", row, cell, style);
							//审计建议
							myCreateCell(3, "", row, cell, style);
							//整改措施
							myCreateCell(4,"", row, cell, style);
							myCreateCell(5,"", row, cell, style);
							//责任部门
							myCreateCell(6,pjEntity!=null?pjEntity.getOrg().getOrgName():"", row, cell, style);
							//整改时间
							myCreateCell(7,"", row, cell, style);
							//责任人
							myCreateCell(8,pjEntity!=null&&pjEntity.getEmployee()!=null?pjEntity.getEmployee().getTrueName():"", row, cell, style);
							rownum++;
					}else{
						while(fxIt.hasNext()){
							int fxRownum=rownum;//发现开始合并单元格的行号
							Object finString=fxIt.next();
							List<AuditProDtlNop> sugList=auditProDtlNopService.findByAuditProNopIdAndAuditEvaluationNoAndAuditFindingNo(auditProId,evaNoString.toString(), finString.toString());//审计建议数据
							AuditProDtlNop fxEntity=sugList.get(0);
									for(AuditProDtlNop ap:sugList){//循环建议
										int jyRownum=rownum;
										List<ZgCsNop> zgcsList=zgCsNopService.findByAuditProDtlNopId(ap.getId());
										if(zgcsList.size()==0){//没有整改措施  
											 row=sheet.createRow(rownum);
												//序号
												myCreateCell(0,rownum+"", row, cell, style);
												//审计监察评价
												myCreateCell(1,StringUtils.isNotBlank(ap.getAuditEvaluation())?ap.getAuditEvaluation():"", row, cell, style);
												//审计发现
												myCreateCell(2,StringUtils.isNoneBlank(ap.getAuditFinding())?ap.getAuditFinding():"", row, cell, style);
												//审计建议
												myCreateCell(3,StringUtils.isNoneBlank(ap.getAuditSuggestion())?ap.getAuditSuggestion():"", row, cell, style);
												//整改措施
												myCreateCell(4,"", row, cell, style);
												myCreateCell(5,"", row, cell, style);
												//责任部门
												myCreateCell(6,ap.getOrg()!=null?ap.getOrg().getOrgName():"", row, cell, style);
												//整改时间
												myCreateCell(7,"", row, cell, style);
												//责任人
												myCreateCell(8,ap!=null&&ap.getEmployee()!=null?ap.getEmployee().getTrueName():"", row, cell, style);
												rownum++;
										}else {
												for(ZgCsNop cs:zgcsList){
													    row=sheet.createRow(rownum);
														//序号
														myCreateCell(0,rownum+"", row, cell, style);
														//审计监察评价
														myCreateCell(1,StringUtils.isNoneBlank(ap.getAuditEvaluation())?ap.getAuditEvaluation():"", row, cell, style);
														//审计发现
														myCreateCell(2,StringUtils.isNotBlank(ap.getAuditFinding())?ap.getAuditFinding():"", row, cell, style);
														//审计建议
														myCreateCell(3,StringUtils.isNoneBlank(ap.getAuditSuggestion())?ap.getAuditSuggestion():"", row, cell, style);
														//整改措施
														myCreateCell(4,StringUtils.isNotBlank(cs.getZgcs())?cs.getZgcs():"", row, cell, style);
														//整改目标
														myCreateCell(5,StringUtils.isNotBlank(cs.getZgmb())?cs.getZgmb():"", row, cell, style);
														//责任部门
														myCreateCell(6,ap.getOrg()!=null?ap.getOrg().getOrgName():"", row, cell, style);
														//整改时间
														myCreateCell(7,cs.getZgPlanTime()!=null?cs.getZgPlanTime().toString():"", row, cell, style);
														//责任人
														myCreateCell(8,ap!=null&&ap.getEmployee()!=null?ap.getEmployee().getTrueName():"", row, cell, style);
														rownum++;
												 }//措施循环结束
										}
										sheet.addMergedRegion(new Region( jyRownum, (short) 3,rownum-1, (short) 3)); 
									}//建议循环结束
							    
							 sheet.addMergedRegion(new Region( fxRownum, (short) 2,rownum-1, (short) 2)); 
							 sheet.addMergedRegion(new Region( fxRownum, (short) 6,rownum-1, (short) 6)); 
							 sheet.addMergedRegion(new Region( fxRownum, (short) 8,rownum-1, (short) 8)); 
						}//发现循环结束
						 sheet.addMergedRegion(new Region(pjRownum, (short) 1,rownum-1, (short) 1)); 
					}//	
				}//评价循环结束
				 
				workbook.write(os);
				os.flush();
				os.close();
				
			}catch(Exception e){
				e.printStackTrace();
			}
		}catch(IOException e){
			e.printStackTrace();
		}
		
		
		
		return null;
	}
	
	/**
	 * 所有RequestMapping方法调用前的Model准备方法, 实现Struts2
	 * Preparable二次部分绑定的效果,先根据form的id从数据库查出Task对象,再把Form提交的内容绑定到该对象上。
	 * 因为仅update()方法的form中有id属性，因此仅在update时实际执行.
	 */
	@ModelAttribute
	public void init(@RequestParam(value = "id", defaultValue = "-1") String id, Model model) {
		if (!id.equals("-1")) {
			model.addAttribute("auditProDtlNop", auditProDtlNopService.getOne(id));
		}
	}
	
	
	public void myCreateCell(int celnum,String value,HSSFRow row,HSSFCell cell,HSSFCellStyle style){
		cell=row.createCell((short)celnum);
		if(StringUtils.isNotBlank(value)){
			cell.setCellValue(new HSSFRichTextString(value));
		}
		cell.setCellStyle(style);
	}
	 
}



